/*
 * @Author: your name
 * @Date: 2020-07-14 10:01:14
 * @LastEditTime: 2020-07-14 10:04:44
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \web3.0\src\utils\storage.js
 */

const ls : Storage = localStorage;
const ss : Storage = sessionStorage;
const db = {
  ls: {
    get(key: string): string | null{
      try {
        let result : any = ls.getItem(key);
        return JSON.parse(result);
      } catch (err) {
        return ls.getItem(key);
      }
    },
    set(key: string, value : string): void {
      ls.setItem(key, JSON.stringify(value));
    },
    remove(key : string): void {
      ls.removeItem(key);
    },
    clear(): void {
      ls.clear();
    }
  },
  ss: {
    get(key: string): string | null{
      try {
        let result : any = ss.getItem(key);
        return JSON.parse(result);
      } catch (err) {
        return ss.getItem(key);
      }
    },
    set(key : string, value : string): void {
      ss.setItem(key, JSON.stringify(value));
    },
    remove(key : string): void{
      ss.removeItem(key);
    },
    clear(): void {
      ss.clear();
    }
  }
};

export default db;
